

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using JTC.MiniCommerce.Localization;
using JTC.MiniCommerce.Store.Web.Controls;
using SubSonic.Utilities;


namespace JTC.MiniCommerce.Web.install.controls {
  public partial class membership : AdminControl {
  
    int step = 0;
    
    protected void Page_Load(object sender, EventArgs e) {
      step = Utility.GetIntParameter("step");
      
      LocalizationUtility.AddPanelText(pnlMembershipSetup);
      LocalizationUtility.AddLabelText(lblMembershipInstructions);
      LocalizationUtility.AddButtonText(btnNext);
      LocalizationUtility.AddButtonText(btnPrevious);  
    }

    protected void btnNext_Click(object sender, EventArgs e) {
      try {
        MembershipCreateStatus status = MembershipCreateStatus.UserRejected;
        Membership.CreateUser(txtUsername.Text.Trim(), txtPassword.Text.Trim(), txtEmail.Text.Trim(), txtSecurityQuestion.Text.Trim(), txtSecurityAnswer.Text.Trim(), true, out status);
        if(status == MembershipCreateStatus.Success) {
          Roles.AddUserToRole(txtUsername.Text.Trim(), "Administrator");
        }
        
        Response.Redirect(string.Format("~/install/install.aspx?step={0}", step + 1), true);
      }
      catch(Exception ex) {
        MasterPage.MessageCenter.DisplayCriticalMessage(LocalizationUtility.GetCriticalMessageText(ex.Message));
      }
    }

    protected void btnPrevious_Click(object sender, EventArgs e) {
      try {
        Response.Redirect(string.Format("~/install/install.aspx?step={0}", step - 1), true);
      }
      catch(Exception ex) {
        MasterPage.MessageCenter.DisplayCriticalMessage(LocalizationUtility.GetCriticalMessageText(ex.Message));
      }
    }    
  }
}